<?php

/**
 * Created by PhpStorm.
 * User: GadflyBSD
 * Date: 16/5/11
 * Time: 12:17
 */
class SchoolLogic extends PublicModel{
	protected $tableName = 'School';

	/**
	 * 递归获得所有校区对应的学校数据
	 * @param int $catid
	 * @param int $item
	 *
	 * @return array
	 */
	public function getAllCategory($catid = 0, $item = 0){
		return array('errcode' => 0, 'data' => $this->getCategory('School', $catid, $item));
	}

	public function getAllArea(){
		return $this->curd(array('model' => M($this->tableName), 'where' => 'upid=0', 'type' => 'select'));
	}

	public function getCategoryInfo($catid){
		return $this->curd(array('model' => M($this->tableName), 'where' => 'catid='.$catid, 'type' => 'find'));
	}

	public function addCategory($post){
		if(!$this->validator('require', $post['upid']))
			return array('errcode' => '300505');
		if(!$this->validator('require', $post['catname']))
			return array('errcode' => '300506');
		if(!$this->validator('require', $post['keyname']))
			return array('errcode' => '300508');
		return $this->curd(array('model' => M($this->tableName), 'type' => 'find', 'data' => $post));
	}

	public function editCategory($where, $post){
		if(!$this->validator('require', $post['upid']))
			return array('errcode' => '300505');
		if(!$this->validator('require', $post['catname']))
			return array('errcode' => '300506');
		if(!$this->validator('require', $post['keyname']))
			return array('errcode' => '300508');
		return $this->curd(array('model' => M($this->tableName), 'type' => 'save', 'where' => $where, 'data' => $post));
	}
}